﻿var _dialog = {};

function GetButtonResourceText(resourceName){
    var resourceTextRequest = {
        "FunctionName": "GetResourceText",
        "ResourceContext": "WebCommon",
        "ResourceName": resourceName
    };
    
    var resourceTextResponse = function (jsonResponse) {
        $("#btnConfirm" + resourceName).html("<span class=\"ui-button-text\">{0}</span>".format(jsonResponse));
    };

    resourceTextRequestManager = new RequestManager(resourceTextRequest, resourceTextResponse, true);
    resourceTextRequestManager.ExecuteRequest();
}

$(function () {
    GetButtonResourceText("Yes");
    GetButtonResourceText("No");
});

function ConfirmationDialog(dialogTitle, yesDelegate) {
    dialogContainerElement = $("<div title=\"{0}\"/>".format(dialogTitle));
    $(dialogContainerElement).append($("<img style=\"float:left;\"/>")
        .attr("src", "/Resources/Images/Icons/question.gif")
        .attr("alt", "question")
        .attr("class", "modalWindowIcon"));
    $(dialogContainerElement).append($("<span/>").attr("id","uxConfirmationText"));

    _dialog = $(dialogContainerElement).dialog({
        autoOpen: false,
        width: 300,
        buttons: [{
            text: "Continue",
            "id": "btnConfirmYes",
            click: function () { 
                $(this).dialog("close");
                yesDelegate();
            }
        }, {
            text: "Cancel",
            "id": "btnConfirmNo",
            click: function () {
                $(this).dialog("close");
            }
        }],        
        modal: true
    });
}

ConfirmationDialog.prototype = {
    yesDelegate: function(){},
    show: function (confirmationText) {
        $("#uxConfirmationText").html(confirmationText);
        _dialog.dialog("open");
    }
}